package com.ittx.dzt.weidian.util;

import cn.hutool.core.util.StrUtil;
import com.ittx.dzt.business.constant.StoreExtendConstant;
import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.sys.util.json.JacksonTool;

import java.util.List;
import java.util.Map;

/**
 * orderType（sale、return）
 * <p>
 *
 * </p>
 *
 * @author wl_code@163.com
 * @version 1.0
 * @date 2025/3/25
 */
public class CyUtil {

	/**
	 * @param platformApiParamDTO
	 * @param orderType           sale 销售单 return 售后单
	 * @return
	 */
	public static String getStatusStr(PlatformApiParamDTO platformApiParamDTO, String orderType) {
		Object status = getStatus(platformApiParamDTO, orderType);
		if (null != status) {
			return String.join(",", (List<String>) status);
		}
		return null;
	}

	public static List<Integer> getStatusList(PlatformApiParamDTO platformApiParamDTO, String orderType) {
		Object status = getStatus(platformApiParamDTO, orderType);
		if (null != status) {
			return (List<Integer>) status;
		}
		return null;
	}

	private static Object getStatus(PlatformApiParamDTO platformApiParamDTO, String orderType) {
		Map<String, Object> extendMap = platformApiParamDTO.getExtendMap();
		if (null != extendMap && extendMap.containsKey(StoreExtendConstant.STATUS_FILTER)) {
			String filterMapStr = extendMap.get(StoreExtendConstant.STATUS_FILTER).toString();
			String filterSetterVal = JacksonTool.toMap(filterMapStr).getOrDefault(orderType, "").toString();
			if (StrUtil.isEmpty(filterSetterVal)) {
				return null;
			}
			Map<String, Object> filterSetterValMap = JacksonTool.toMap(filterSetterVal);
			Map<String, Object> filterMap = (Map<String, Object>) filterSetterValMap.get("filter");
			return filterMap.get("order_status");
		}
		return null;
	}
}
